/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.MessageManager;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.util.Map;
/*    */ import javax.servlet.RequestDispatcher;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ public class UpdateWhiteBoard extends AbstractAction
/*    */ {
/* 20 */   private int id = 0;
/*    */ 
/*    */   public UpdateWhiteBoard(AbstractHttpServlet servlet) {
/* 23 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public UpdateWhiteBoard(AbstractHttpServlet servlet, String id) {
/* 27 */     super(servlet);
/* 28 */     this.id = Util.str2Int(id);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 35 */     String title = Util.getURLParameter(request.getParameter("title"));
/* 36 */     String message = Util.getURLParameter(request.getParameter("message"));
/* 37 */     int visible = Util.getURLIntParameter(request.getParameter("visible"));
/* 38 */     String attachFiles = Util.getURLParameter(request
/* 39 */       .getParameter("attachFiles"));
/* 40 */     String permissionsId = "";
/*    */ 
/* 42 */     MessageManager manager = new MessageManager();
/*    */ 
/* 44 */     Map item = manager.getDetail(this.id);
/* 45 */     if (item == null) {
/* 46 */       request.getRequestDispatcher("/errorpage.jsp").forward(request, 
/* 47 */         response);
/* 48 */       return;
/*    */     }
/*    */ 
/* 51 */     String createUserId = (String)item.get("CreateUserId");
/* 52 */     Integer messageType = (Integer)item.get("MessageType");
/* 53 */     boolean flag = checkRight(super.getLoginUser(request), 
/* 54 */       createUserId, messageType);
/* 55 */     if (!flag) {
/* 56 */       request.getRequestDispatcher("/errorpage.jsp").forward(request, 
/* 57 */         response);
/* 58 */       return;
/*    */     }
/*    */ 
/* 61 */     manager.update(this.id, title, message, attachFiles, visible, 
/* 62 */       permissionsId);
/* 63 */     response.sendRedirect(request.getContextPath() + "/whiteboard/" + 
/* 64 */       this.id);
/*    */   }
/*    */ 
/*    */   private boolean checkRight(User u, String createUserId, Integer messageType) {
/* 68 */     if (messageType.intValue() == 1) {
/* 69 */       return false;
/*    */     }
/*    */ 
/* 72 */     if (u.isAdmin) {
/* 73 */       return true;
/*    */     }
/*    */ 
/* 77 */     return u.userId.equals(createUserId);
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.UpdateWhiteBoard
 * JD-Core Version:    0.6.1
 */